<html>
<head><meta charset="utf-8"><title>Usage of pin-project in stdlib · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html">Usage of pin-project in stdlib</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225101605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225101605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225101605">(Feb 04 2021 at 00:01)</a>:</h4>
<p>Hi all,</p>
<p>I'm currently working on some more involved async adapters, and I was wondering how to go about using <code>pin-project</code> in the stdlib. I'm assuming this is something we want to do, since without it it'd be much harder to validate we're correctly using <code>Pin</code> (essentially all of the async ecosystem makes use of <code>pin-project</code>). But I'm not sure how to go about adding a dependency to the stdlib?</p>
<p>Does anyone have any guidance on how to add <code>pin-project</code> as a dep to stdlib?</p>
<p>cc/ <span class="user-mention" data-user-id="213313">@Taiki Endo</span> probably as well</p>



<a name="225102283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225102283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225102283">(Feb 04 2021 at 00:09)</a>:</h4>
<p>Naively tried including <code>pin-project-lite</code> as a dependency of <code>core</code>, but that fails compilation. Which makes sense since I'm assuming <code>pin-project-lite</code> depends on <code>core</code>. The solution would probably be to inline the source somehow, but I'm guessing there's processes around this, and probably requires coordinating with the crate maintainers.</p>



<a name="225102641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225102641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225102641">(Feb 04 2021 at 00:13)</a>:</h4>
<p>crates that are to be used as part of core/stdlib generally expose a feature that makes it usable in that context.</p>



<a name="225102746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225102746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225102746">(Feb 04 2021 at 00:14)</a>:</h4>
<p>see <code>rustc-dep-of-std</code> for <code>libc</code> or <code>hashbrown</code>.</p>



<a name="225102835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225102835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225102835">(Feb 04 2021 at 00:15)</a>:</h4>
<p>this typically involves making the crate <code>#[no_std]</code> if used in libstd or <code>#[no_core]</code> if used in <code>libcore</code>.</p>



<a name="225103152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225103152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225103152">(Feb 04 2021 at 00:19)</a>:</h4>
<p>The other more generic concerns are: license compatibility and maintainership. The crates currently part of libstd are part of the rust-lang organisation, for various reasons.</p>



<a name="225103205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225103205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225103205">(Feb 04 2021 at 00:20)</a>:</h4>
<p>cfg-if is a macro-only rustc-dep-of-std that would probably work similarly to pin-project-lite</p>



<a name="225121887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225121887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taiki Endo <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225121887">(Feb 04 2021 at 05:53)</a>:</h4>
<p><span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span></p>
<p>First, I have two questions.</p>
<ol>
<li>Which crate are you actually planning to use? (pin-project or pin-project-lite)</li>
<li>Which crate are you actually planning to use pin-project* with? (std, alloc, core, or other)</li>
</ol>
<p>In general, as for 1, my recommendation as an author of both crates is to use pin-project whenever possible. See <a href="https://github.com/rust-lang/futures-rs/issues/2170#issuecomment-755208805">https://github.com/rust-lang/futures-rs/issues/2170#issuecomment-755208805</a> and <a href="https://github.com/tokio-rs/tracing/issues/1178#issuecomment-760337757">https://github.com/tokio-rs/tracing/issues/1178#issuecomment-760337757</a> for reasons.</p>
<p>However, if 1 is pin-project, I'm not sure what we need to use proc-macro with std or core.</p>
<p>If 1 is pin-project-lite and 2 is <em>not</em> core, it's relatively easy (IIUC). <a href="https://github.com/taiki-e/pin-project-lite/compare/master...rustc-dep-of-std">https://github.com/taiki-e/pin-project-lite/compare/master...rustc-dep-of-std</a></p>
<p>If 1 is pin-project-lite and 2 is core, I think it's possible, but it requires a breaking change to pin-project-lite. I can accept this, but not immediately. (I know a way that to avoid breaking changes, but I don't like it way.)</p>
<p>Also, I don't know about the policy for adding dependencies to the standard library, but if there's anything I can do please let me know. (The license should be fine.)</p>



<a name="225132886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225132886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225132886">(Feb 04 2021 at 08:53)</a>:</h4>
<p><span class="user-mention" data-user-id="213313">@Taiki Endo</span> I'd prefer <code>pin-project</code> for 1, and I'm looking to use it in <code>core</code> for 2.</p>



<a name="225133206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225133206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225133206">(Feb 04 2021 at 08:56)</a>:</h4>
<p>The reason for that is that most <code>Future</code> / <code>Stream</code> combinators van be exposed from that layer, since we never allocate.</p>



<a name="225133797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225133797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225133797">(Feb 04 2021 at 09:03)</a>:</h4>
<p><span class="user-mention" data-user-id="213313">@Taiki Endo</span> what <span class="user-mention" data-user-id="123586">@nagisa</span> is saying probably is what's needed to make this work: enable the crate to work on <code>#[no_core]</code>, and then ensure the licenses are compatible and the Rust org can maintain them. I think you are the right person to help with these; though it feels like a big ask <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="225175296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225175296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225175296">(Feb 04 2021 at 15:33)</a>:</h4>
<p>I am not sure it's possible to have std depend on a proc macro. Proc macros at a minimum need the <code>proc_macro</code> crate. Even if that works out <code>no_core</code> is a <em>very</em> large ask that will probably end up duplicating most of the core crate.</p>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> will know more about this than me.</p>



<a name="225175520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225175520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225175520">(Feb 04 2021 at 15:35)</a>:</h4>
<p>It'll be annoying but it's not infeasible I think, no need for no_core I think - I don't have the bandwidth to help out right now though.</p>



<a name="225175806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225175806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225175806">(Feb 04 2021 at 15:36)</a>:</h4>
<p>My worry is for stage 1 builds where we haven't built libstd yet and can't use the beta libstd. Proc macros still use a standard library IIUC</p>
<p>(Does that mean build scripts for libstd must have <code>no_std</code>?)</p>



<a name="225176369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225176369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225176369">(Feb 04 2021 at 15:40)</a>:</h4>
<p>the proc macro crate would use the previous stage's libstd just like the compiler does</p>



<a name="225176438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225176438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225176438">(Feb 04 2021 at 15:41)</a>:</h4>
<p>just like when cross compiling proc macro crates are built for the host, not the target</p>



<a name="225177543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225177543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225177543">(Feb 04 2021 at 15:49)</a>:</h4>
<p>I don't see how that can work - the proc macro is being compiled by stage1, but libstd was compiled by beta. The ABI is different.</p>



<a name="225236186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225236186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225236186">(Feb 04 2021 at 22:52)</a>:</h4>
<p><code>pin-project-lite</code> is a <code>macro_rules</code> macro, and prior experience points to it being enough for most cases we'd want to cover here. Would that be easier to include?</p>



<a name="225237670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225237670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225237670">(Feb 04 2021 at 23:05)</a>:</h4>
<p>yes, much</p>



<a name="225331512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/225331512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#225331512">(Feb 05 2021 at 17:43)</a>:</h4>
<p>Filed a PR which could make use of <code>pin-project-lite</code>. This contains a concrete example for why we'd want this available in <code>core</code>: <a href="https://github.com/rust-lang/rust/pull/81797">https://github.com/rust-lang/rust/pull/81797</a></p>



<a name="226231626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/226231626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taiki Endo <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#226231626">(Feb 13 2021 at 07:14)</a>:</h4>
<p><span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span> Thanks for the response.</p>
<blockquote>
<p>The reason for that is that most Future / Stream combinators van be exposed from that layer, since we never allocate.</p>
</blockquote>
<p>That makes sense. However, as mentioned in the above comment, pin-project-lite can't provide no-core support right away, so I recommend adding to std first (by using pin-project-lite's rustc-dep-of-std feature) instead of using unsafe code. I can promise to provide no-core support for pin-project-lite before the feature stabilizes.</p>
<blockquote>
<p>what nagisa is saying probably is what's needed to make this work: enable the crate to work on #[no_core], and then ensure the licenses are compatible and the Rust org can maintain them.</p>
</blockquote>
<p>I'm okay with move the repository and add write/publish permissions to T-libs (if I can keep accessing the repo as admin).<br>
For other things, I think I already answered these in the above comment.</p>



<a name="226284284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/226284284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taiki Endo <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#226284284">(Feb 14 2021 at 04:00)</a>:</h4>
<p><a href="https://rustc-dev-guide.rust-lang.org/crates-io.html#cratesio-dependencies">The policy on adding dependencies to the compiler</a> does not seem to mention the repository/crate owner, but the library may have another stricter policy...</p>



<a name="226299745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/226299745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#226299745">(Feb 14 2021 at 11:27)</a>:</h4>
<p>It's not a hard requirement since for example <a href="https://github.com/gimli-rs/object">https://github.com/gimli-rs/object</a> is a dependency of std.</p>



<a name="226536858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Usage%20of%20pin-project%20in%20stdlib/near/226536858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Usage.20of.20pin-project.20in.20stdlib.html#226536858">(Feb 16 2021 at 16:27)</a>:</h4>
<p><span class="user-mention" data-user-id="213313">@Taiki Endo</span> sounds good; I'll update my PR be on <code>std</code> for now then</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>